#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

bool P(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i <= sqrt(n); ++i) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int N(int n) {
    if (P(n)) {
        return n;
    }
    int l = n - 1;
    int u = n + 1;
    while (true) {
        if (P(l)) {
            return l;
        } else if (P(u)) {
            return u;
        }
        l--;
        u++;
    }
}

int main() {
    vector<string> w(3);
    string s;
    for (int i = 0; i < 3; ++i) {
        cin >> s;
        w[i] = s;
    }
    vector<string> d = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

    try {
        vector<int> i(3);
        for (int j = 0; j < 3; ++j) {
            auto it = find(d.begin(), d.end(), w[j]);
            if (it != d.end()) {
                i[j] = distance(d.begin(), it);
            } else {
                throw runtime_error("Wrong input");
            }
        }
        int n = i[0] * 100 + i[1] * 10 + i[2];
        cout << N(n) << endl;

    } catch (const runtime_error& e) {
        cerr << e.what() << endl;
    }

    return 0;
}
